#include<iostream>
#include<vector>
#include<unordered_map>
using namespace std;

class Solution {
public:
    vector<vector<string>> groupAnagrams(vector<string>& strs) {
        int len = strs.size();
        unordered_map<string, int> hash;
        int pos = 0;
        vector<vector<string>> ans;
        for (int i = 0; i < len; i++) {
            string tmps = strs[i];
            sort(tmps.begin(), tmps.end());
            if (hash.count(tmps) == 0) {
                hash[tmps] = pos;
                ans.push_back({ strs[i] });
                pos++;
            }
            else {
                ans[hash[tmps]].push_back(strs[i]);
            }
        }
        return ans;
    }
};

